package sh.exception;


import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import sh.dto.Response;
import sh.dto.ResultDto;

@ControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(SystemException.class)
    @ResponseBody
    public ResultDto systemExceptionHandler(SystemException e){
        return Response.error(e.getCode(), e.getMsg());
    }

    /**
     * 捕获系统异常-非ajax请求
     * @param e
     * @return
     */
  /*  @ExceptionHandler(NoAjaxException.class)
    public ModelAndView noAjaxExceptionHandler(NoAjaxException e){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error");
        return modelAndView;
    }*/


//    @ExceptionHandler(Exception.class)
//    @ResponseBody
//    public ResultDto ExceptionHandler(Exception e){
//        System.out.println(e.getMessage());
//        return Response.error(1003,"未知错误");
//    }

}
